package com.dz.syndata.task;

import com.dz.syndata.bean.device.DeviceBean;
import com.dz.syndata.service.IDeviceInfoService;
import com.dz.syndata.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;


@Component
@EnableScheduling
public class TimerTask {
    @Autowired
    IDeviceInfoService mDeviceInfoService;

    /**
     * 默认是fixedDelay 上一次执行完毕时间后执行下一轮
     * 每1小时执行该方法
     * 水情
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void runWaterData() throws InterruptedException {
        mDeviceInfoService.insertData();

    }

    /**
     *  0 0 0 * * ?每天凌晨12点执行
     *  改为 0 0 2 * * ? 每天凌晨两点执行
     * @throws InterruptedException
     */
//   @Scheduled(cron = "0 0 0 * * ?")
   @Scheduled(cron = "0 0 2 * * ?")
    public void selectWaterData() throws InterruptedException {
//        mDeviceInfoService.selectRainfall();
        mDeviceInfoService.updateRainfall(DateUtils.getDate());
    }


}
